% rm_dum_pts 
% Chris Whalen
% University of Illinois
% 07/30/04

% Purpose - removes dummy elp points (those that are not in the src or det files) and returns the opt_label and the xyz arrays without them


function [opt_label,xyz,num_dum_pts]=rm_dum_pts(src,det,opt_label,xyz)

%fprintf('\n rm_dum_pts');
fprintf('\nRemoving Dummy Elp Points...\n(Dummy Points are points found in the elp file but not in the montage file)\n');
j=4;  % temp_opt_label index: starts after 1st 3 fiducials
temp_opt_label = opt_label; % Preallocating 
temp_xyz = xyz;
for i_opt_label=4:length(opt_label) % Start Past 3 Fiducials
    for i_src=1:length(src) % Searching to see if label is source
        if strcmp(src(i_src),opt_label(i_opt_label))==1
            temp_opt_label(j,1) = opt_label(i_opt_label);
            temp_xyz(j,:) = xyz(i_opt_label,:);
            j=j+1;
        end
    end
    for i_det=1:length(det) % Searching to see if label is detector
         if strcmp(det(i_det),opt_label(i_opt_label))==1
            temp_opt_label(j,1) = opt_label(i_opt_label);
            temp_xyz(j,:) = xyz(i_opt_label,:);
            j=j+1;
         end
     end
end

temp_opt_label(j:length(opt_label)) = []; % Removing excess preallocated rows
num_dum_pts = length(opt_label)-length(temp_opt_label);
temp_xyz(j:length(opt_label),:) = []; 
opt_label = temp_opt_label;
xyz = temp_xyz;

fprintf('\nNumber of Dummy Points Removed: %d\n\n',num_dum_pts);

